﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using WinformToolkit.Navigations;

namespace WinformClient
{
    public partial class MainForm : Form, IContentHost
    {
        #region 构造方法

        public MainForm()
        {
            InitializeComponent();

            MenuManager.RegisterMenu("menu.json", this);
        }

        #endregion

        #region INavigationHost

        public event Action<IContentHost, WinformToolkit.Navigations.WFMenuItem> MenuClicked;

        public void AddContent(IContentControl content)
        {
            (content as UserControl).Dock = DockStyle.Fill;
            PanelContent.Controls.Add(content as Control);
        }

        public void RemoveContent(IContentControl content)
        {
            PanelContent.Controls.Remove(content as Control);
        }

        public void InitializeMenuList(List<WinformToolkit.Navigations.WFMenuItem> menuList)
        {
            foreach (WinformToolkit.Navigations.WFMenuItem item in menuList)
            {
                ListBoxNavigation.Items.Add(item);
            }
        }

        #endregion

        #region 事件处理器

        private void ListBoxNavigation_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (this.MenuClicked != null)
            {
                this.MenuClicked(this, ListBoxNavigation.SelectedItem as WinformToolkit.Navigations.WFMenuItem);
            }
        }

        #endregion

        private void tabControl1_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            MessageBox.Show("123");
        }
    }
}
